<?php

require_once("common.inc.php");

$qrURL = "http://chart.apis.google.com/chart?cht=qr&chs=350x350&chld=L|0&chl=";
$bll = BLL::getInstance();

if (empty($_GET["q"])) {
	printf("<html><head></head><body><ul>");
	foreach ($bll->getAll("Question") as $question) {
		printf("<li><a href=\"%s?q=%s\">QR van vraag %s</a></li>\n", $_SERVER["PHP_SELF"], $question->id, $question->id);
	}
	printf("</body></html>\n");
} else {
	$question = $bll->getQuestionByID($_GET["q"]);
	$url = generateQuestionURL($question);
	header("Content-Type: image/png");
	header(sprintf("Content-Disposition: inline; filename=question%s.png", $question->id));
	// todo verify syntax of Content-Disposition header
	// todo call zxing barcode generator
	print(file_get_contents($qrURL . urlencode($url)));
}
